
using System;
using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using Csla.Validation;

namespace SariturIntranetLibrary.Teinamentos
{
    [Serializable()]
    public class TreinamentoChildInfo : Csla.ReadOnlyBase<TreinamentoChildInfo>
    {

        #region Business Properties and Methods

        //declare members

        private Guid _id = Guid.NewGuid();

        private string _titulo = string.Empty;

        private SmartDate _dataDoTreinamento = new SmartDate(false);

        private string _chamada = string.Empty;

        private string _descricao = string.Empty;

        private string _informacoes = string.Empty;

        [System.ComponentModel.DataObjectField(true, false)]
        public Guid Id
        {
            get
            {
                CanReadProperty("Id", true);
                return _id;
            }
        }

        public string Titulo
        {
            get
            {
                CanReadProperty("Titulo", true);
                return _titulo;
            }
        }

        public DateTime DataDoTreinamento
        {
            get
            {
                CanReadProperty("DataDoTreinamento", true);
                return _dataDoTreinamento.Date;
            }
        }

        public string DataDoTreinamentoString
        {
            get
            {
                CanReadProperty("DataDoTreinamentoString", true);
                return _dataDoTreinamento.Text;
            }
        }

        public string Chamada
        {
            get
            {
                CanReadProperty("Chamada", true);
                return _chamada;
            }
        }

        public string Descricao
        {
            get
            {
                CanReadProperty("Descricao", true);
                return _descricao;
            }
        }

        public string Informacoes
        {
            get
            {
                CanReadProperty("Informacoes", true);
                return _informacoes;
            }
        }

        protected override object GetIdValue()
        {
            return _id;
        }

        #endregion //Business Properties and Methods

        #region Authorization Rules
        protected override void AddAuthorizationRules()
        {
            //TODO: Define authorization rules in TreinamentoChildInfo
            //AuthorizationRules.AllowRead("Id", "TreinamentoChildInfoReadGroup");
            //AuthorizationRules.AllowRead("Titulo", "TreinamentoChildInfoReadGroup");
            //AuthorizationRules.AllowRead("DataDoTreinamento", "TreinamentoChildInfoReadGroup");
            //AuthorizationRules.AllowRead("DataDoTreinamentoString", "TreinamentoChildInfoReadGroup");
            //AuthorizationRules.AllowRead("Chamada", "TreinamentoChildInfoReadGroup");
            //AuthorizationRules.AllowRead("Descricao", "TreinamentoChildInfoReadGroup");
            //AuthorizationRules.AllowRead("Informacoes", "TreinamentoChildInfoReadGroup");

        }

        #endregion //Authorization Rules

        #region Factory Methods
        internal static TreinamentoChildInfo GetTreinamentoChildInfo(SafeDataReader dr)
        {
            return new TreinamentoChildInfo(dr);
        }

        private TreinamentoChildInfo(SafeDataReader dr)
        {
            Fetch(dr);
        }
        #endregion //Factory Methods


        #region Data Access

        #region Data Access - Fetch
        private void Fetch(SafeDataReader dr)
        {
            FetchObject(dr);

            //load child object(s)
            FetchChildren(dr);

        }

        private void FetchObject(SafeDataReader dr)
        {
            _id = dr.GetGuid("Id");
            _titulo = dr.GetString("Titulo");
            _dataDoTreinamento = dr.GetSmartDate("DataDoTreinamento", _dataDoTreinamento.EmptyIsMin);
            _chamada = dr.GetString("Chamada");
            _descricao = dr.GetString("Descricao");
            _informacoes = dr.GetString("Informacoes");
        }

        private void FetchChildren(SafeDataReader dr)
        {
        }
        #endregion //Data Access - Fetch
        #endregion //Data Access
    }
}
